home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2005 November / WNnov2005.iso / Windows / Equipement / hMailServer / hMailServer-4.1-Build-136.exe / {app} / PHPWebAdmin / index.php < prev    next >
Encoding:
PHP Script  |  2005-07-14  |  12.2 KB  |  276 lines

  1. <?php
  2. /*
  3. ** $Id: index.php,v 1.14 2005/07/14 10:35:55 hmailserver Exp $
  4. **
  5. **    hMailServer - Web interface
  6. **
  7. **    File formatted using TAB size 4
  8. **
  9. **    Get hMailserver at http://www.hmailserver.com
  10. **
  11. **    Author: Steen Rab°l <srabol@mail.tele.dk>
  12. **    Copyright (c) 2004, Steen Rab°l <srabol@mail.tele.dk>
  13. **
  14. **  This program is free software; you can redistribute it and/or modify
  15. **  it under the terms of the GNU General Public License as published by
  16. **  the Free Software Foundation; either version 2 of the License, or
  17. **  (at your option) any later version.
  18. **
  19. **  You may not change or alter any portion of this comment or credits
  20. **  of supporting developers from this source code or any supporting
  21. **  source code which is considered copyrighted (c) material of the
  22. **  original comment or credit authors.
  23. **
  24. **  This program is distributed in the hope that it will be useful,
  25. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27. **  GNU General Public License for more details.
  28. **
  29. **  You should have received a copy of the GNU General Public License
  30. **  along with this program; if not, write to the Free Software
  31. **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  32. **
  33. */
  34.  
  35. if (!file_exists("config.php"))
  36. {
  37.     echo "Please rename config-dist.php to config.php. The file is found in the PHPWebAdmin root folder.";
  38.     die;
  39. }
  40.  
  41. require_once("config.php");
  42. require_once("mhwainit.php");
  43.  
  44. $loggedin = hmailGetVar("loggedin",0);
  45. $hmailSmarty->assign("loggedin",$loggedin);
  46. $page = hmailGetVar("page","frontpage");
  47. if ($loggedin != 1)
  48. {
  49.     $page = "login";
  50.     $page    = $page . ".php";
  51.     $maintemplate = "login.tpl";
  52.     require_once($page);
  53. }
  54. else
  55. {
  56.     $page    = $page . ".php";
  57.     require_once($page);
  58.     $maintemplate = "index.tpl";
  59.  
  60.     // Build tree menu
  61.     $obSettings    = $obBaseApp->Settings();
  62.     $obDomains    = $obBaseApp->Domains();
  63.     
  64.     $DomainCount = $obDomains->Count();
  65.     $dtitem=0;
  66.  
  67.     $dtree = "d.add(" . $dtitem++ .",-1,'" . hmailGetLocaleText("welcome") . "','index.php','" . hmailGetLocaleText("welcome") ."');\r\n";
  68.     
  69.     if (hmailGetAdminLevel() == 0)
  70.     {
  71.         // User     
  72.         $domainname = hmailGetUserDomainName($_SESSION['username']);
  73.         
  74.         $obDomain = $obBaseApp->Domains->ItemByName($domainname);
  75.         $obAccounts = $obDomain->Accounts;
  76.         $obAccount    = $obAccounts->ItemByAddress($_SESSION['username']);
  77.         
  78.         $url = htmlentities("index.php?page=accounts_edit&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID);
  79.         $di = $dtitem++;
  80.         $dtree .= "d.add($di,0,'" . $obAccount->Address . "','$url','','','" . $hmail_config['themepath'] . "images/user.gif','" . $hmail_config['themepath'] . "images/user.gif');\r\n";
  81.         $dtree .= "d.add(" . $dtitem++ . ",$di,'" . hmailGetLocaleText("auto_reply") . "','index.php?page=accounts_autoreply&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
  82.     }
  83.  
  84.     
  85.     if (hmailGetAdminLevel() == 1)
  86.     {
  87.         // Domain
  88.         
  89.         $dtree .= "d.add(" . $dtitem++ .",0,'" . hmailGetLocaleText("domains") . "','','','','" . $hmail_config['themepath'] . "images/s_host.png','" . $hmail_config['themepath'] . "images/s_host.png');\r\n";
  90.  
  91.         $domainname = hmailGetUserDomainName($_SESSION['username']);
  92.         
  93.         $obDomain = $obBaseApp->Domains->ItemByName($domainname);
  94.         $domain_root = $dtitem++;
  95.         
  96.         GetStringForDomain($obDomain);
  97.     }
  98.         
  99.     if (hmailGetAdminLevel() == 2)
  100.     {
  101.         // Server
  102.         
  103.         $dtree .= "d.add(" . $dtitem++ .",0,'" . hmailGetLocaleText("domains") . " ($DomainCount)','index.php?page=domains','','','" . $hmail_config['themepath'] . "images/s_host.png','" . $hmail_config['themepath'] . "images/s_host.png');\r\n";
  104.             
  105.         for ($i = 1; $i <= $DomainCount; $i++)
  106.         {
  107.             $obDomain = $obBaseApp->Domains[$i-1];
  108.             $domain_root = $dtitem++;
  109.  
  110.             GetStringForDomain($obDomain);
  111.         }
  112.     
  113.         
  114.         $dtree .= "d.add(" . $dtitem++ . ",0,'" . hmailGetLocaleText("server") . "','index.php?page=services','','','" . $hmail_config['themepath'] ."images/globe.gif');\r\n";
  115.         $dtree .= "d.add(" . $dtitem++ . ",0,'" . hmailGetLocaleText("mx_query") . "','index.php?page=mxquery');\r\n";
  116.         $settings_root = $dtitem++;
  117.         $dtree .= "d.add(" . $settings_root . ",0,'" . hmailGetLocaleText("settings") . "','index.php?page=settings','','','" . $hmail_config['themepath'] . "images/settings.gif','" . $hmail_config['themepath'] . "images/settings.gif');\r\n";
  118.         $settings_smtp_root = $dtitem++;
  119.         $dtree .= "d.add(" . $settings_smtp_root . ",$settings_root,'" . hmailGetLocaleText("smtp") . "','index.php?page=settings_smtp');\r\n";
  120.         $dtree .= "d.add(" . $dtitem++ . ",$settings_smtp_root,'" . hmailGetLocaleText("security") . "','index.php?page=settings_smtp_security');\r\n";
  121.         $dtree .= "d.add(" . $dtitem++ . ",$settings_smtp_root,'" . hmailGetLocaleText("antivirus") . "','index.php?page=settings_smtp_antivirus');\r\n";
  122.         $settings_smtp_route    = $dtitem++;
  123.     
  124.         $obRoutes    = $obSettings->Routes();
  125.         $Count = $obRoutes->Count();
  126.         $dtree .= "d.add(" . $settings_smtp_route . ",$settings_smtp_root,'" . hmailGetLocaleText("routes") . " (" . $Count . ")','index.php?page=settings_smtp_routes');\r\n";
  127.     
  128.         for ($i = 0; $i < $Count; $i++)
  129.         {
  130.             $obRoute = $obRoutes->Item($i);
  131.             $di = $dtitem++;
  132.             $dtree .= "d.add($di,$settings_smtp_route,'" . $obRoute->DomainName . "','index.php?page=settings_smtp_routes_edit&RouteID=" . $obRoute->ID . "');\r\n";
  133.             $dsub = $dtitem++;
  134.             $dtree .= "d.add($dsub,$di,'" . hmailGetLocaleText("addresses") . "','index.php?page=settings_smtp_routes_addresses&RouteID=" . $obRoute->ID . "');\r\n";
  135.             $dsub = $dtitem++;
  136.             $dtree .= "d.add($dsub,$di,'" . hmailGetLocaleText("delivery") . "','index.php?page=settings_smtp_routes_delivery&RouteID=" . $obRoute->ID . "');\r\n";
  137.         }
  138.     
  139.         $dtree .= "d.add(" . $dtitem++ . ",$settings_root,'" . hmailGetLocaleText("pop3") . "','index.php?page=settings_pop3');\r\n";
  140.         $dtree .= "d.add(" . $dtitem++ . ",$settings_root,'" . hmailGetLocaleText("imap") . "','index.php?page=settings_imap');\r\n";
  141.     
  142.         $obSecurityRanges    = $obSettings->SecurityRanges();
  143.         $obSecurityRanges->Refresh();
  144.         $Count = $obSecurityRanges->Count();
  145.     
  146.         $settings_ipranges_root = $dtitem++;
  147.         $dtree .= "d.add(" . $settings_ipranges_root . ",$settings_root,'" . hmailGetLocaleText("ip_ranges") . " ($Count)','index.php?page=settings_ipranges');\r\n";
  148.     
  149.         for ($j = 0; $j < $Count; $j++)
  150.         {
  151.             $obSecurityRange = $obSecurityRanges->Item($j);
  152.             $di = $dtitem++;
  153.             $dtree .= "d.add($di,$settings_ipranges_root,'" . $obSecurityRange->Name . "','index.php?page=settings_ipranges_edit&IPRangeID=" . $obSecurityRange->ID . "');\r\n";
  154.         }
  155.         $dtree .= "d.add(" . $dtitem++ . ",$settings_root,'" . hmailGetLocaleText("logging") . "','index.php?page=settings_logging');\r\n";
  156.         $dtree .= "d.add(" . $dtitem++ . ",$settings_root,'" . hmailGetLocaleText("mirror") . "','index.php?page=settings_mirror');\r\n";
  157.         $tools_root = $dtitem++;
  158.         $dtree .= "d.add(" . $tools_root . ",0,'" . hmailGetLocaleText("tools") . "','index.php?page=tools','','','" . $hmail_config['themepath'] . "images/tools.png','" . $hmail_config['themepath'] . "images/tools.png');\r\n";
  159.         $dtree .= "d.add(" . $dtitem++ . ",$tools_root,'" . hmailGetLocaleText("backup") . "','index.php?page=tools_backup');\r\n";
  160.         $dtree .= "d.add(" . $dtitem++ . ",$tools_root,'" . hmailGetLocaleText("restore") . "','index.php?page=tools_restore');\r\n";
  161.     
  162.         // Plugins
  163.         // Scan the plugin dir for files
  164.         $plugins = getFilesInDir($hmail_config['pluginpath']);
  165.     
  166.         if(is_array($plugins) && count($plugins) >0)
  167.         {
  168.             $plugins_root = $dtitem++;
  169.             $dtree .= "d.add(" . $plugins_root . ",0,'" . hmailGetLocaleText("plugins") . "','','','','" . $hmail_config['themepath'] . "images/tools.png','" . $hmail_config['themepath'] . "images/tools.png');\r\n";
  170.     
  171.             // read plugins
  172.             foreach($plugins as $plugin)
  173.             {
  174.                 $menufunc = basename($plugin,".php") . "_menu";
  175.                 $pluginname = str_replace("plugin_","",basename($plugin,".php"));
  176.                 $includefile = $hmail_config['pluginpath'] . $plugin;
  177.                 include_once($includefile);
  178.                 $menuname = $menufunc();
  179.                 $dtree .= "d.add(" . $dtitem++  . ",$plugins_root,'" . $menuname . "','index.php?page=plugin&plugin=$pluginname','','','" . $hmail_config['themepath'] . "images/tools.png','" . $hmail_config['themepath'] . "images/tools.png');\r\n";
  180.             }
  181.         }
  182.     }
  183.     
  184.     $dtree .= "d.add(" . $dtitem++ .",-1,'" . hmailGetLocaleText("logout") . "','logout.php','" . hmailGetLocaleText("logout") ."');\r\n";
  185.     
  186.     $dtree .= "document.write(d);";
  187.     $hmailSmarty->assign("dtree",$dtree);
  188. }
  189.  
  190. function GetStringForDomain($obDomain)
  191. {
  192.     // I know this is ugly... / Martin
  193.     global $dtree, $domain, $dtitem, $domain_root, $hmail_config;
  194.     
  195.     $dtree .= "d.add($domain_root,1,'" . $obDomain->Name . "','index.php?page=domain_edit&DomainID=" . $obDomain->ID . "','','','" . $hmail_config['themepath'] . "images/b_home.png','" . $hmail_config['themepath'] . "images/b_home.png');\r\n";
  196.  
  197.     $obAccounts     = $obDomain->Accounts();
  198.     $AccountsCount    = $obAccounts->Count();
  199.     $accounts_root = $dtitem++;
  200.     $dtree .= "d.add($accounts_root,$domain_root,'" . hmailGetLocaleText("accounts") . " ($AccountsCount)','index.php?page=accounts&DomainID=" . $obDomain->ID . "','','','" . $hmail_config['themepath'] . "images/b_usrlist.png','" . $hmail_config['themepath'] . "images/b_usrlist.png');\r\n";
  201.     for ($j = 0; $j < $AccountsCount; $j++)
  202.     {
  203.         $obAccount    = $obAccounts->Item($j);
  204.         $di = $dtitem++;
  205.         $url = htmlentities("index.php?page=accounts_edit&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID);
  206.         $dtree .= "d.add($di,$accounts_root,'" . $obAccount->Address . "','$url','','','" . $hmail_config['themepath'] . "images/user.gif','" . $hmail_config['themepath'] . "images/user.gif');\r\n";
  207.         $dtree .= "d.add(" . $dtitem++ . ",$di,'" . hmailGetLocaleText("auto_reply") . "','index.php?page=accounts_autoreply&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
  208.         $dtree .= "d.add(" . $dtitem++ . ",$di,'" . hmailGetLocaleText("active_directory") . "','index.php?page=accounts_activedirectory&AccountID=" . $obAccount->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
  209.     }
  210.  
  211.     $obAliases        = $obDomain->Aliases();
  212.     $AliasesCount    = $obAliases->Count();
  213.     $aliases_root    = $dtitem++;
  214.     $dtree .= "d.add($aliases_root,$domain_root,'" . hmailGetLocaleText("aliases") . " ($AliasesCount)','index.php?page=alias&DomainID=" . $obDomain->ID . "');\r\n";
  215.  
  216.     for ($j = 0; $j < $AliasesCount; $j++)
  217.     {
  218.         $obAlias    = $obAliases->Item($j);
  219.         $di = $dtitem++;
  220.         $dtree .= "d.add($di,$aliases_root,'" . $obAlias->Name . "','index.php?page=alias_edit&AliasID=" . $obAlias->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
  221.     }
  222.  
  223.     $obDistributionLists    = $obDomain->DistributionLists();
  224.     $DListCount                = $obDistributionLists->Count();
  225.     $dlist_root                = $dtitem++;
  226.     $dtree .= "d.add($dlist_root,$domain_root,'" . hmailGetLocaleText("distribution_lists") . " ($DListCount)','index.php?page=distributionlists&DomainID=" . $obDomain->ID . "');\r\n";
  227.  
  228.     for ($j = 0; $j < $DListCount; $j++)
  229.     {
  230.         $obDistributionList    = $obDistributionLists->Item($j);
  231.         $di = $dtitem++;
  232.         $dtree .= "d.add($di,$dlist_root,'" . $obDistributionList->Address .  "','index.php?page=distributionlists_edit&DistributionlistID=" . $obDistributionList->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
  233.         $dtree .= "d.add(" . $dtitem++ .",$di,'" . hmailGetLocaleText("recipients") . " (" . $obDistributionList->Recipients->Count() . ")','index.php?page=distributionlists_recipients&DistributionlistID=" . $obDistributionList->ID . "&DomainID=" . $obDomain->ID. "');\r\n";
  234.     }        
  235.     
  236.     
  237. }
  238.  
  239. function getFilesInDir($p_path)
  240. {
  241.     $files = array();
  242.     if(is_readable($p_path))
  243.     {
  244.         // Open current directory
  245.         if($handle = opendir($p_path))
  246.         {
  247.             // Loop through all files
  248.             while(false !== ($file = readdir($handle)))
  249.             {
  250.                 // Ignore hidden files
  251.                 if(!preg_match("/^\./", $file))
  252.                 {
  253.                     // Put dirs in $dirs[] and files in $files[]
  254.                     if(!is_dir($file))
  255.                     {
  256.                         $files[] = $file;
  257.                     }
  258.                 }
  259.             }
  260.  
  261.             // Close directory
  262.             closedir($handle);
  263.             // if $files[] exists, sort it and print all elements in it.
  264.             if(is_array($files))
  265.             {
  266.                 sort($files);
  267.             }
  268.         }
  269.     }
  270.  
  271.     return $files;
  272. }
  273. $hmailSmarty->display($maintemplate);
  274.  
  275. ?>
  276.